home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPPLIB.ZIP / WINTOOL.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  5KB  |  183 lines

  1. // wintool.cpp -- Select window attributes
  2.  
  3. //#include <stream.hpp>
  4. #include <stdio.h>
  5. #include "wintool.h"
  6.  
  7. /* -- Global variables */
  8.  
  9. int attributes[6] = {1, 15, 7, 0, 7, 0};
  10. unsigned wta = 0x1f;
  11. unsigned wba = 0x70;
  12. unsigned wha = 0x70;
  13. cwindow *mainWindow;
  14. cwindow *sampleWindow;
  15.  
  16. main()
  17. {
  18.   cwindow::startup();
  19.   createMainWindow();
  20.   createSampWindow();
  21.   performCommands();
  22.   delete sampleWindow;
  23.   delete mainWindow;
  24.   cwindow::shutDown();
  25.   exit(0);
  26. }
  27.  
  28. /* -- Create and display main program window */
  29.  
  30. void createMainWindow()
  31. {
  32.   winStruct ws = {
  33.     0, 0, 80, 25,  // row, column, width, height
  34.     0x07,          // text attribute
  35.     0x0f,          // border attribute
  36.     0x70,          // highlight attribute
  37.     3              // border type
  38.   };
  39.  
  40.   mainWindow = new cwindow(
  41.     ws, " Window Design Tool from \"Learning C++\" by Tom Swan ");
  42.   mainWindow->showWindow();
  43. }
  44.  
  45. /* -- Create and display sample window */
  46.  
  47. void createSampWindow()
  48. {
  49.   winStruct ws = {
  50.     SAMP_ROW, SAMP_COL, SAMP_WIDTH, SAMP_HEIGHT,
  51.     wta, wba, wha, SAMP_TYPE
  52.   };
  53.  
  54.   sampleWindow = new cwindow(ws, SAMP_TITLE);
  55.   sampleWindow->showWindow();
  56. }
  57.  
  58. /* -- Create command menu and execute command objects */
  59.  
  60. void performCommands(void)
  61. {
  62.   command *cp;         // Pointer to selected command
  63.   winStruct ws = {
  64.     MENU_ROW, MENU_COL, MENU_WIDTH, MENU_HEIGHT,
  65.     MENU_TA, MENU_BA, MENU_HA, MENU_TYPE
  66.   };
  67.   selector *menu = new selector(ws, MENU_TITLE, MENU_POPUP);
  68.  
  69.   menu->insertItem(new helpCommand());
  70.   menu->insertItem(new attrCommand(" Text Background",       CMD_TBG));
  71.   menu->insertItem(new attrCommand(" Text Foreground",       CMD_TFG));
  72.   menu->insertItem(new attrCommand(" Border Background",     CMD_BBG));
  73.   menu->insertItem(new attrCommand(" Border Foreground",     CMD_BFG));
  74.   menu->insertItem(new attrCommand(" Highlight Background",  CMD_HBG));
  75.   menu->insertItem(new attrCommand(" Highlight Foreground",  CMD_HFG));
  76.   showColors();
  77.   while ((cp = (command *)(menu->getSelection())) != NULL) {
  78.     cp->performCommand();
  79.     showColors();
  80.   }
  81. }
  82.  
  83. /* -- Display current color attributes and sample window */
  84.  
  85. void showColors(void)
  86. {
  87.   for (int i = 0; i < 6; i++) {
  88.     mainWindow->gotorc(MENU_ROW + i + 1, MENU_COL + MENU_WIDTH);
  89.     mainWindow->puts(dec(attributes[i]));
  90.   }
  91.   mainWindow->gotorc(16, 4);
  92.   mainWindow->puts("Text attribute ........ : 0x");
  93.   mainWindow->puts(hex(wta));
  94.   mainWindow->gotorc(17, 4);
  95.   mainWindow->puts("Border attribute ...... : 0x");
  96.   mainWindow->puts(hex(wba));
  97.   mainWindow->gotorc(18, 4);
  98.   mainWindow->puts("Highlight attribute ... : 0x");
  99.   mainWindow->puts(hex(wha));
  100.   showSample();
  101. }
  102.  
  103. /* -- Display sample window using selected attributes */
  104.  
  105. void showSample(void)
  106. {
  107.   winStruct ws = {
  108.     SAMP_ROW, SAMP_COL, SAMP_WIDTH, SAMP_HEIGHT,
  109.     wta, wba, wha, SAMP_TYPE
  110.   };
  111.  
  112.   sampleWindow->setInfo(ws);
  113.   sampleWindow->gotorc(0, 0);
  114.   sampleWindow->eeow();
  115.   sampleWindow->gotorc(5, 9);
  116.   sampleWindow->normalVideo();
  117.   sampleWindow->puts("Normal Text");
  118.   sampleWindow->gotorc(10, 6);
  119.   sampleWindow->reverseVideo();
  120.   sampleWindow->puts(" Highlighted Text ");
  121. }
  122.  
  123. /* -- Implementation of the help command */
  124.  
  125. void helpCommand::performCommand(void)
  126. {
  127.   winStruct ws = {
  128.     2, 2, 76, 21,  // row, column, width, height
  129.     0x1f,          // text attribute
  130.     0x70,          // border attribute
  131.     0x70,          // highlight attribute
  132.     0              // border type
  133.   };
  134.   cwindow *helpWindow = new cwindow(ws, " WinTool Help ");
  135.  
  136.   helpWindow->showWindow();
  137.   helpWindow->gotorc(8, 4);
  138.   helpWindow->puts("No help available");
  139.   helpWindow->gotorc(10, 4);
  140.   helpWindow->puts("(Press <Esc> from main menu to quit program)");
  141.   while (!keyWaiting()) ;
  142.   getKey();
  143.   delete helpWindow;
  144. }
  145.  
  146. /* -- Implementation of the attributes command. Increments attribute
  147. value for selected item, identified by cmdNum. Updates global window
  148. attribute values. */
  149.  
  150. void attrCommand::performCommand(void)
  151. {
  152.   attributes[cmdNum] = ++attributes[cmdNum] % 16;
  153.   wta = attributes[0] * 16 + attributes[1];
  154.   wba = attributes[2] * 16 + attributes[3];
  155.   wha = attributes[4] * 16 + attributes[5];
  156. }
  157.  
  158. /* -- Return 2-digit decimal string */
  159. char *dec(int n)
  160. {
  161.   static char string[2];
  162.  
  163.   sprintf(string, "%2d", n);
  164.   return (char *)string;
  165. }
  166.  
  167. /* -- Return 2-digit hexadecimal string */
  168. char *hex(unsigned int n)
  169. {
  170.   static char string[2];
  171.  
  172.   sprintf(string, "%2x", n);
  173.   return (char *)string;
  174. }
  175.  
  176.  
  177. // Copyright (c) 1990 by Tom Swan. All rights reserved
  178. // Revision 1.00    Date: 09/29/1990   Time: 02:15 pm
  179.  
  180. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  181. // Converted for Borland C++ 2.0
  182.  
  183.